package com.itheima.studentproject.dao;

import com.itheima.studentproject.domain.Student;

public class StudentDao {
    private static Student[] arr = new Student[5];

    public boolean addStudent(Student student){
        boolean flag = false;

        for (int i = 0; i < arr.length; i++) {
            Student stu1 = arr[i];
            if(stu1 == null){
                arr[i] = student;
                flag = true;
                break;
            }
        }

        return flag;
    }

    public Student[] findAll() {
        return arr;
    }

    public boolean updateStudent(Student stu) {
        for (int i = 0; i < arr.length; i++) {
            Student student = arr[i];
            if (student != null) {
                if(stu.getId().equals(student.getId())){
                    arr[i] = stu;
                    return true;
                }
            }
        }
        return false;
    }

    public boolean deleteStudent(int index) {
        arr[index] = null;
        return true;
    }
}
